﻿using FtpUploadWeb.Common;
using Microsoft.AspNetCore.Mvc;
using Quartz;
using Quartz.Impl;
using Quartz.Util;
using System;
using System.IO;
using System.Text;

namespace FtpUploadWeb.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            ViewBag.user = "hj";
            return View();
        }

        public IActionResult SchedulerStart()
        {
            TaskManage.ResumeAll();
            return Ok("作业启动");
        }

        public IActionResult SchedulerShutdown()
        {
            TaskManage.PauseAll();
            return Ok("停止作业");
        }

        public IActionResult ResumeJobBackup()
        {
            TaskManage.ResumeJobBackup();
            return Ok("备份作业已启动");
        }

        public IActionResult PauseJobBackup()
        {
            TaskManage.PauseJobBackup();
            return Ok("备份作业已停止");
        }

        public IActionResult ResumeJobBat()
        {
            TaskManage.ResumeJobBat();
            return Ok("批处理作业已启动");
        }

        public IActionResult PauseJobBat()
        {
            TaskManage.PauseJobBat();
            return Ok("批处理作业已停止");
        }

        //显示日志文件
        public IActionResult Message()
        {
            var logFilePath = TaskManage.GetLogFile();
            StreamReader sr = new StreamReader(logFilePath);//用FileStream对象实例化一个StreamReader对象
            var strLine = sr.ReadLine();//  读取一行字符并返回
            var str = "";
            while (strLine != null)
            {
                Console.WriteLine(strLine);
                strLine = sr.ReadLine();
                str += strLine + "\r\n";
            }
            sr.Close();

            return Ok(str);
        }
    }
}